import { createRouter, createWebHistory } from 'vue-router'
import config from '../config'
import systemRoutes from './modules/system'

const BASE = config.base

// 项目路由
const projectRoutes = [
  // { path: ``, component: () => import('../views/Home.vue') }
]

/**
 * 自动导入modules文件夹下的路由
 */
const modules = import.meta.globEager('./modules/*.js')
const filter = ['./modules/system.js']
for (const key in modules) {
  if (Object.hasOwnProperty.call(modules, key) && !filter.includes(key)) {
    const element = modules[key]
    projectRoutes.push(...element.default)
  }
}

// 路由信息
const routes = [
  { path: ``, redirect: `${BASE}` },
  {
    path: `${BASE}/login`,
    component: () => import('jax-node/views/login/login.vue'),
  },
  {
    path: `${BASE}`,
    // component: () => import('jax-ui/layout/Layout.vue'),
    component: () => import('../views/admin/Layout.vue'),
    children: [...systemRoutes, ...projectRoutes],
  },
]

// 导出路由
const router = createRouter({
  history: createWebHistory(),
  routes,
})

export default router
